/*
 * ADC.c
 *
 * Created: 05-03-2012 13:59:00
 *  Author: Bjarke
 */ 

#include <avr/io.h>
#include "ADC.h"


void InitADC()
{
  // PA pins are inputs (ADC)
  DDRA = 0;
  // Internal 5 volt reference, ADLAR = 0, Input = ADC0 single ended
  ADMUX = 0b01000000;
  // ADC enable
  // ADC interrupt disabled
  // ADC prescaler = 32 (=> ADC clock = 3,6864 MHz / 32 = 115 kHZ)
  ADCSRA = 0b10000101;
}


int readADC(char num)
{
ADMUX |= num; 
	// Start new AD conversion
	ADCSRA |= 0b01000000;
	// Wait for AD conversion ended
	while (ADCSRA & 0b01000000)
	{}
	// Read ADC result and send value to UART
	return (ADCW);
}